<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" @keyup.enter.native="searchQuery">
        <a-row :gutter="24">
          <a-col :md="6" :sm="8">
            <a-form-item label="维度名称">
              <j-input placeholder="请输入维度名称" v-model="queryParam.dimensionName" />
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <a-form-item label="维度类型">
               <a-select
                  placeholder="请选择维度类型"
                  allow-clear
                  v-model="queryParam.dictType"
                  :getPopupContainer="trigger => trigger.parentNode"
                >
                <a-select-option :value="item.id" :key="item.id" v-for="item in dictTypes">
                      {{ item.name }}
                  </a-select-option>
                </a-select>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="8">
            <span style="float: left; overflow: hidden" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>
    <!-- 查询区域-END -->

    <!-- 操作按钮区域 -->
    <div class="table-operator">
      <a-button @click="handleAdd" type="primary" icon="plus">新增</a-button>
      <a-button type="primary" icon="download" @click="handleExportXls('维度详情表')">导出</a-button>
      <a-button @click="batchDel" type="primary" icon="delete">批量删除</a-button>
      <!-- 高级查询区域 -->
      <j-super-query
        :fieldList="superFieldList"
        ref="superQueryModal"
        @handleSuperQuery="handleSuperQuery"
      ></j-super-query>
    </div>

    <!-- table区域-begin -->
    <div>
      <a-alert type="info" showIcon style="margin-bottom: 16px">
        <template slot="message">
          <span>已选择</span>
          <a style="font-weight: 600; padding: 0 4px">{{ selectedRowKeys.length }}</a>
          <span>项</span>
          <a style="margin-left: 24px" @click="onClearSelected">取消勾选</a>
        </template>
      </a-alert>

      <a-table
        ref="table"
        size="middle"
        :scroll="{ x: true }"
        bordered
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        class="j-table-force-nowrap"
        @change="handleTableChange"
      >
        <!-- 状态渲染模板 -->
        <template slot="customRenderStatus" slot-scope="status">
          <a-tag v-if="status == 0" color="red">停用</a-tag>
          <a-tag v-if="status == 1" color="green">启用</a-tag>
        </template>

        <template slot="dictType" slot-scope="dictType">
          <span v-if="dictType == 1" >根据系统字典</span>
          <span v-if="dictType == 3" >自定义字典</span>
          <span v-if="dictType == 0" >无字典</span>
        </template>

        <span slot="action" slot-scope="text, record">
          <a @click="handleEdit(record)">编辑</a>
          <a-divider type="vertical" />
          <a-popconfirm placement="topLeft" title="确定删除吗?" @confirm="() => handleDelete(record.id)">
            <a>删除</a>
          </a-popconfirm>
        </span>
      </a-table>
    </div>

    <DimensionInfoModal ref="modalForm" @ok="modalFormOk" />
  </a-card>
</template>

<script>

import '@/assets/less/TableExpand.less'
import { mixinDevice } from '@/utils/mixin'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'
import DimensionInfoModal from './modules/DimensionInfoModal'

export default {
  name: 'ScSituationDimensionInfoList',
  components: {
    DimensionInfoModal
  },
  mixins: [JeecgListMixin, mixinDevice],
  data() {
    return {
      dictTypes: [
        { id: 1, name: '根据系统字典' },
        { id: 3, name: '自定义字典' },
        { id: 0, name: '无字典' }
      ],
      description: '维度定义页面',
      // 表头
      columns: [
        {
          title: '#',
          dataIndex: '',
          key: 'rowIndex',
          width: 60,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: '维度名称',
          align: 'center',
          dataIndex: 'dimensionName'
        },
        {
          title: '维度类型',
          align: 'center',
          dataIndex: 'dictType',
          scopedSlots: { customRender: 'dictType' }
        },
        {
          title: '字典编号',
          align: 'center',
          dataIndex: 'dictCode'
        },
        {
          title: '字典表',
          align: 'center',
          dataIndex: 'dictTable'
        },
        {
          title: '字典值',
          align: 'center',
          dataIndex: 'dictValue'
        },
        {
          title: '状态',
          align: 'center',
          dataIndex: 'status',
          scopedSlots: { customRender: 'customRenderStatus' },
          filterMultiple: false,
          filters: [
            { text: '停用', value: '0' },
            { text: '启用', value: '1' }
          ]
        },
        {
          title: '创建人',
          align: 'center',
          dataIndex: 'createBy'
        },
        {
          title: '创建日期',
          align: 'center',
          dataIndex: 'createTime'
        },
        {
          title: '备注',
          align: 'center',
          dataIndex: 'remark'
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          fixed: 'right',
          width: 180,
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/dimension/scSituationDimensionType/list',
        delete: '/dimension/scSituationDimensionType/delete',
        deleteBatch: '/dimension/scSituationDimensionType/deleteBatch',
        exportXlsUrl: '/dimension/scSituationDimensionType/exportXls',
        importExcelUrl: '/dimension/scSituationDimensionType/importExcel'

      },
      dictOptions: {},
      superFieldList: []
    }
  },
  computed: {
    importExcelUrl: function() {
      return `${window._CONFIG['domianURL']}/${this.url.importExcelUrl}`
    }
  },
  created() {
    this.getSuperFieldList()
  },
  methods: {
    initDictConfig() {
    },
    getSuperFieldList() {
      const fieldList = []
      fieldList.push({ type: 'string', value: 'dimensionName', text: '维度名称', dictCode: '' })
      fieldList.push({ type: 'string', value: 'createBy', text: '创建人', dictCode: '' })
      fieldList.push({ type: 'datetime', value: 'createTime', text: '创建日期', dictCode: '' })
      fieldList.push({ type: 'string', value: 'remark', text: '备注', dictCode: '' })
      this.superFieldList = fieldList
    }
  }
}
</script>
<style scoped>
@import '~@assets/less/common.less';
</style>
